﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace BattleMaster_IRCbot.UserCommands
{
    class Login : Command
    {
        public override string Name { get { return _name; } }
        public override string[] Aliasses { get { return _aliasses; } }
        public override string Description { get { return _description; } }
        public override string ShortDesc { get { return _shortDesc; } }

        public Login()
        {
            _name = "Login";
            _aliasses = new string[] { "logon" };
            _description = "Use this command to log into your character.\n Once you have done so, you can begin using game-time commands.";
            _shortDesc = "Use this command to log into your character.";
        }

        public override void Verb(Game game, string msgOrigen, string[] cmd)
        {
            if (msgOrigen != "console")
            {
                bool loggedIn = false;
                foreach (Character C in game.Characters)
                {
                    if (C.Name == msgOrigen)
                    {
                        loggedIn = true;
                        break;
                    }
                }
                if (!loggedIn)
                {
                    try
                    {
                        game.addCharacter(msgOrigen);
                        game.ircHandler.sendNotice(msgOrigen, "You are now logged in.");
                    }
                    catch (DirectoryNotFoundException ex) { game.ircHandler.sendNotice(msgOrigen,ex.Message); }
                    catch (FileNotFoundException ex) { game.ircHandler.sendNotice(msgOrigen,String.Format("Character file for {0} not found.", msgOrigen)); }
                }
                else game.ircHandler.sendNotice(msgOrigen,"You are already logged in.");
            }
        }
    }
}
